package com;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Calender {
    public static void main(String[] args) {
        JFrame jf = new JFrame("考勤日历");
        jf.setSize(400, 300);
        jf.setDefaultCloseOperation(3);
        jf.setLocationRelativeTo(null);
        jf.setAlwaysOnTop(true);
        jf.setLayout(null);
        DateChooser dateChooser = DateChooser.getInstance();
        DateChooser dateChooser2= DateChooser.getInstance();

        JLabel date=new JLabel("考勤日期");
        date.setBounds(50,20,100,20);
        jf.add(date);

        JLabel starttime=new JLabel("开始时间");
        starttime.setBounds(50,70,100,20);
        jf.add(starttime);

        JLabel endtime=new JLabel("结束时间");
        endtime.setBounds(250,70,100,20);
        jf.add(endtime);

        JTextField start=new JTextField();
        start.setBounds(50,100,100,20);
        dateChooser.register(start);
        jf.add(start);

        JTextField end=new JTextField();
        end.setBounds(250,100,100,20);
        dateChooser2.register(end);
        jf.add(end);


        JButton ok=new JButton("确定");
        ok.setBounds(250,180,60,20);
        jf.add(ok);
        ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String start1=start.getText();
                String end1=end.getText();
                if(start1.isEmpty()||end1.isEmpty())
                {
                    JOptionPane.showMessageDialog(jf,"日期为空,请重新输入");
                    return;
                }
                SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
                try {
                    Date starttime=sdf.parse(start1);
                    Date endtime=sdf.parse(end1);
                    JOptionPane.showMessageDialog(jf,starttime+"\n"+endtime);
                } catch (ParseException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        jf.setVisible(true);




    }
}
